package com.tianji.learning.service.impl;

import com.tianji.api.client.user.UserClient;
import com.tianji.api.dto.user.UserDTO;
import com.tianji.common.utils.CollUtils;
import com.tianji.learning.domain.entity.InteractionQuestion;
import com.tianji.learning.interfaces.UserIdFunction;
import com.tianji.learning.service.UserQueryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@Slf4j
@Service
public class UserQueryServiceImpl implements UserQueryService {
    @Autowired
    private UserClient userClient;
    @Override
    public Map<Long, UserDTO> getUserMap(List<? extends UserIdFunction> list) {
        Map<Long, UserDTO> userMap = new HashMap<>();
        List<Long> userIds = list.stream().map(UserIdFunction::getUserId).collect(Collectors.toList());
        List<UserDTO> userDTOS = userClient.queryUserByIds(userIds);
        if (!CollUtils.isEmpty(userDTOS)) {
            userMap = userDTOS.stream().collect(Collectors.toMap(UserDTO::getId, Function.identity()));
        }
        return userMap;
    }
}
